<html xmlns:py="http://genshi.edgewall.org/" py:strip="">
  <py:choose>
    <hr class="prelisting" />
    <table py:when="len(discussion.topics)" class="listing">
      <thead>
        <tr id="lower">
          ${sortable_th_nc(discussion.order, discussion.desc, 'subject', 'Subject', href.discussion('forum', discussion.forum.id))}
          ${sortable_th_nc(discussion.order, discussion.desc, 'topic_author', 'Author', href.discussion('forum', discussion.forum.id))}
          ${sortable_th_nc(discussion.order, discussion.desc, 'replies', 'Replies', href.discussion('forum', discussion.forum.id))}
          ${sortable_th_nc(discussion.order, discussion.desc, 'viewcount', 'Views', href.discussion('forum', discussion.forum.id))}
          ${sortable_th_nc(discussion.order, discussion.desc, 'lastreply', 'Last Post', href.discussion('forum', discussion.forum.id))}
        </tr>
      </thead>
      <tbody>
        <tr py:for="line, topic in enumerate(discussion.topics)" class="${line % 2 and 'forumlistrow_even' or 'forumlistrow_odd'}">
          <td class="forumlist_subject">
            <div class="subject">

                <span py:for="visualstatus in topic.visualstatus">${visualstatus}</span>

              <a href="${href.discussion('topic', topic.id)}">
                <span>${topic.subject or 'No subject'}</span>
              </a>
            </div>
              <div class="founded">
                  <span>
                    ${fromtimestamp(topic.time).strftime("%a %d %b, %Y %H:%M:%S")}
                  </span>


                  <py:if test="int((int(topic.replies or '1')+1)/discussion.messages_per_page)+1 > 2"> 
                      <a py:for="page in reversed(range(1, int((int(topic.replies or '1')+1)/discussion.messages_per_page)+2))" href="${req.base_path}/discussion/topic/${topic.id}?discussion_page=${page}" class="pagelink">
                        ${page}
                      </a>
                  </py:if>
                  
                  <span py:if="topic.new_replies > 0" class="topicnewtag">NEW</span>
              </div>
          </td>
          <td class="forumlist_author">
            <div class="author">
                <py:choose test="len(topic.author)">
                  <py:when test="0">
                    <span>&nbsp;</span>
                  </py:when>                
                  <py:otherwise>
                    ${format_author(topic.author)}
                  </py:otherwise>
                </py:choose>
            </div>
          </td>
          <td class="forumlist_replies">
            <div class="replies">
              <span>${topic.replies or '0'}</span>
            </div>
          </td>
          <td class="forumlist_views">
            <div class="views">
              <span>${topic.viewcount or '0'}</span>
            </div>
          </td>
          <td class="forumlist_lastreply">
            <div class="container_lastreply">
            <div class="lastreplier">
                <a href="${conf.url_home_path}/user/${topic.lastreplier or topic.author}">${format_author(topic.lastreplier) or format_author(topic.author)}</a>
            </div>
            <div class="lastmodified">
                ${topic.lastreply and fromtimestamp(topic.lastreply).strftime("%a %d %b, %Y %H:%M:%S") or 'no replies'}
            </div>
            </div>
            <div class="container_lastlink">
              <a class="lastmessagelink" href="${req.base_path}/discussion/topic/${topic.id}#lastmessage">
                <span >&raquo;</span>
              </a>
            </div>
          </td>
        </tr>
      </tbody>
    </table>
    <hr class="postlisting" />
          <py:otherwise>
            <div class="greyBgContainer">
              <div class="greyBgContent">
                <span style="font-weight: bold;">There are no topics created in this forum.</span><br/>
                <a py:if="(discussion.forum.name != conf.news_forum_name and 'DISCUSSION_APPEND' in perm) or (discussion.forum.name == conf.news_forum_name and 'DISCUSSION_ANNOUNCEAPPEND' in perm)" href="javascript:clickNewTopic()">Create one!</a>
              </div>
            </div>
          </py:otherwise>
  </py:choose>
</html>
